#pragma once
#include <pthread.h>

namespace LockModule
{
    class Mutex
    {
    public:
        const Mutex &operator==(const Mutex &) = delete;
        Mutex(const Mutex &) = delete;
        Mutex()
        {
            int n = pthread_mutex_init(&_lock, nullptr);
            (void)n;
        }

        void Lock()
        {
            int n = pthread_mutex_lock(&_lock);
            (void)n;
        }

        void UnLock()
        {
            int n = pthread_mutex_unlock(&_lock);
        }

        pthread_mutex_t *LockPtr()
        {
            return &_lock;
        }

        ~Mutex()
        {
        }

    private:
        pthread_mutex_t _lock;
    };

    class LockGuard
    {
    public:
        LockGuard(Mutex &mtx) : _mtx(mtx)
        {
            _mtx.Lock();
        }

        ~LockGuard()
        {
            _mtx.UnLock();
        }

    private:
        Mutex &_mtx;
    };
}